/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} head
 * @return {boolean}
 */
 var hasCycle = function(head) {
    if(!head){
        return false;
    }
    let first=head.next,second=head;
    while(first!=second){
        if(first==null || first.next==null){
            return false;
        }
        first=first.next.next;
        second=second.next;
    }
    return true;
};
/*  var hasCycle = function(head) {
    let set = new Set();
    while(head!=null){
        if(set.has(head)){
            return true;
        }
        else{
            set.add(head);
        }
        head=head.next;
    }
    return false;
}; */